/**
 * Created by 37500 on 2017/8/24.
 */
import React from 'react';
import './head.scss';

class HelloMessage extends React.Component {
    constructor(props) {
        super(props);
        this.state  = {
            count : 1
        };
        this.handleClick = this.handleClick.bind(this);
    }
    handleClick() {
        var that = this;
        var timer = null;
        var isCounting = false;
        if(isCounting) {
            return
        }
        timer = setInterval(function() {
            isCounting = true;
            var count = that.state.count;
            count++;
            if(count == 10) {
                clearInterval(timer);
                that.setState({
                    count : 0
                });
                isCounting = false;
                return
            }

            that.setState(prevState => ({
                count : count
            }))
        }, 1000);

    }
    render() {
        return <div className={this.props.className} onClick={this.handleClick}>Hello {this.props.name || 'xixi'} <p>{this.state.count}</p></div>
    }
}

export default HelloMessage
